<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>菜单编辑</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/libs/layui2.2.5/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/common.css">
    <link rel="icon" href="href="${pageContext.request.contextPath}/static/libs/uiframe/frame/static/image/code.png">
</head>
<body>
    <form class="layui-form" style="padding-top: 20px;padding-right: 20px;" action="">
        <input type="hidden" name="parentId" value="${parentId}"/>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称：</label>
            <div class="layui-input-block">
                <input type="text" name="menuName" value="${menu.menuName}"
                       autocomplete="off" placeholder="请输入菜单名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单类型：</label>
            <div class="layui-input-block">
                <c:choose>
                    <c:when test="${menu.menuType == 0}">
                        <input type="radio" name="menuType" value="0" title="菜单" checked="checked">
                        <input type="radio" name="menuType" value="1" title="按钮">
                    </c:when>
                    <c:when test="${menu.menuType == 1}">
                        <input type="radio" name="menuType" value="0" title="菜单">
                        <input type="radio" name="menuType" value="1" title="按钮"  checked="checked">
                    </c:when>
                    <c:otherwise>
                        <input type="radio" name="menuType" value="0" title="菜单" checked="checked">
                        <input type="radio" name="menuType" value="1" title="按钮">
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">链接：</label>
            <div class="layui-input-block">
                <input type="text" name="href" value="${menu.href}"
                       autocomplete="off" placeholder="请输入菜单链接" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">目标：</label>
            <div class="layui-input-block">
                <input type="text" name="target" value="${menu.target}"
                       autocomplete="off" placeholder="请输入菜单目标" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图标：</label>
            <div class="layui-input-block">
                <input type="text" name="icon" value="${menu.icon}"
                       autocomplete="off" placeholder="请输入菜单图标" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否显示：</label>
            <div class="layui-input-block">
                <c:choose>
                    <c:when test="${menu.isShow == 'true'}">
                        <input type="radio" name="isShow" value="true" title="是"  checked="checked">
                        <input type="radio" name="isShow" value="false" title="否">
                    </c:when>
                    <c:when test="${menu.isShow == 'false'}">
                        <input type="radio" name="isShow" value="true" title="是">
                        <input type="radio" name="isShow" value="false" title="否" checked="checked">
                    </c:when>
                    <c:otherwise>
                        <input type="radio" name="isShow" value="true" title="是" checked="checked">
                        <input type="radio" name="isShow" value="false" title="否">
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序编号：</label>
            <div class="layui-input-block">
                <c:choose>
                    <c:when test="${menu.sortedNum != null}">
                        <input type="text" name="sortedNum"
                               value="${menu.sortedNum}" placeholder="" autocomplete="off" class="layui-input">
                    </c:when>
                    <c:otherwise>
                        <input type="text" name="sortedNum"
                               value=0 placeholder="" autocomplete="off" class="layui-input">
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述：</label>
            <div class="layui-input-block">
                <textarea name="description" value="${menu.description}"
                          placeholder="请输入描述内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="roleadd">提 交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
            </div>
        </div>
    </form>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/libs/layui2.2.5/layui.js"></script>
<script>
    var menuId = '${menu.menuId}',parentId = '${parentId}',appId = '${appId}';

    layui.use(['form','layer'],function(){
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;

            //监听提交
        form.on('submit(roleadd)', function(data){
            var formData = data.field,url;
            if(menuId == ""){
                url = '${pageContext.request.contextPath}/sys/menu/menucreate?appid=${appId}';
            }else{
                url = '${pageContext.request.contextPath}/sys/menu/menucreate?appid=${appId}';
            }
            $.ajax({
                type:'post',
                dataType:'json',
                url:url,
                data:{
                    parentId:formData['parentId'],
                    menuId:menuId,
                    menuName:formData['menuName'],
                    menuType:formData['menuType'],
                    href:formData['href'],
                    target:formData['target'],
                    icon:formData['icon'],
                    isShow:formData['isShow'],
                    sortedNum:formData['sortedNum'],
                    description:formData['description']
                },
                success:function (data) {
                    layer.msg(data.status);
                    window.parent.layIndex = null;
                    window.parent.closeAllLayer();
                },
                error:function (error) {
                    console.log(error);
                }
            });
            return false;
        });
    })
</script>
</body>
</html>
